package com.navinfo.tripanalysis.offline.service;

import com.navinfo.tripanalysis.common.pojo.PointProtocol;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.types.StructField;
import org.apache.spark.sql.types.StructType;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 统一协议落盘数据类型转换接口
 * @author hmc
 */
public interface PointProtocolConvertService extends Serializable {


    /*
    * 创建统一协议数据Row
     */
    Row toRow(PointProtocol p);
    /*
    * Row生成
     */
    PointProtocol fromRow(Row row);
    //创建落盘数据结构列表
    List<StructField> createStructTypeList();
    //加载分区字段
    List<String> getPartitionCols();
    //创建统一协议Schema
    default StructType createSchema(List<StructField> list){return new StructType(list.toArray(new StructField[0]));}
    //创建Schema名称列表
    default List<String> getColNamesList(List<StructField> list)
    {
        List<String> colsName = new ArrayList<>();
        list.forEach(e -> colsName.add(e.name()));
        return colsName;
    }
}
